﻿'         This file is Copyright © 2008-2012 Billy O'Neal and Aommaster
'                            All rights reserved.
'
' This file is released under the 2-Clause BSD license, included in LICENSE.TXT
'                           and on the MHWT website
Option Compare Text
Imports System.Security.Cryptography

Friend Class Hasher
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim browser As OpenFileDialog = New OpenFileDialog()

        If browser.ShowDialog() = DialogResult.OK Then
            filepath.Text = browser.FileName
            dohash()
        End If
    End Sub

    Private Sub dohash()
        Dim md5hasher As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
        Dim sha1hasher As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider
        Dim fs As System.IO.FileStream
        Dim bytehash As Byte()
        Dim hash As String

        fs = New System.IO.FileStream(filepath.Text, IO.FileMode.Open)
        bytehash = md5hasher.ComputeHash(fs)
        hash = System.BitConverter.ToString(bytehash).Replace("-", "")
        md5hash.Text = hash
        fs.Close()

        fs = New System.IO.FileStream(filepath.Text, IO.FileMode.Open)
        bytehash = sha1hasher.ComputeHash(fs)
        hash = System.BitConverter.ToString(bytehash).Replace("-", "")
        sha1hash.Text = hash

        fs.Close()



    End Sub

    Private Sub md5check_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles md5check.TextChanged
        If md5check.Text = md5hash.Text Then
            md5match.Image = My.Resources.yes
        Else
            md5match.Image = My.Resources.no
        End If
    End Sub

    Private Sub sha1check_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sha1check.TextChanged
        If sha1check.Text = sha1hash.Text Then
            sha1match.Image = My.Resources.yes
        Else
            sha1match.Image = My.Resources.no
        End If
    End Sub
End Class